package com.jblog.user.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.jblog.common.BaseDaoImpl;
import com.jblog.user.model.User;

@Repository
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao{

	@Autowired
	HibernateTemplate ht;
	
	
	@Override
	public User selectUserByLogin(String loginName) {
		DetachedCriteria d = DetachedCriteria.forClass(User.class);
		d.add(Restrictions.or(Restrictions.eq("username", loginName),Restrictions.eq("email", loginName),Restrictions.eq("phone", loginName)));
		System.out.println(d.getAlias());
		List<User> list = (List<User>) ht.findByCriteria(d);
		if(list == null || list.size() == 0 || list.get(0) == null){
			return null;
		}
		return list.get(0);
	}

	
	
}
